#include "../include/tree.h"

#include <stdio.h>

Status output( TElemType e )
{
    printf( "%d", e );
    return OK;
}

Status CreateTree( BiTree *T )
{
    return OK;
}

Status PreOrderTraverse( BiTree T, Visit pCallBack )
{
    if ( T ) {
        if ( pCallBack( T->data ) == OK
                && PreOrderTraverse( T->lchild, pCallBack ) == OK
                && PreOrderTraverse( T->rchild, pCallBack ) == OK ) {
            return OK;
        } else {
            return ERROR;
        }
    } else {
        return OK;
    }

}

Status InOrderTraverse( BiTree T, Visit pCallBack )
{
    if ( T ) {
        if ( InOrderTraverse( T->lchild, pCallBack ) == OK
                && pCallBack( T->data ) == OK
                && InOrderTraverse( T->rchild, pCallBack ) == OK ) {
            return OK;
        } else {
            return ERROR;
        }
    } else {
        return OK;
    }
}

Status PostOrderTraverse( BiTree T, Visit pCallBack )
{
    if ( T ) {
        if ( PostOrderTraverse( T->lchild, pCallBack ) == OK
                && PostOrderTraverse( T->rchild, pCallBack ) == OK
                && pCallBack( T->data ) == OK ) {
            return OK;
        } else {
            return ERROR;
        }
    } else {
        return OK;
    }
}

// use queue
Status LevelOrderTraverse( BiTree T, Visit pCallBack )
{
    return OK;
}

// use stack
Status InOrderTraverseNoRecursion( BiTree T, Visit pCallBack )
{
    // 	BiTNode *p = NULL;
    // 	ListStack S;
    // 	InitStack(&S);
    //
    // 	Push(&S, T);

    return OK;

}
